/*
 * 描述： <描述>
 * 修改人： rain
 * 修改时间： 2016年8月9日
 * 项目： rainhy-servicelogger
 */
package com.rainhy.servicelogger.interceptor;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.rainhy.servicelogger.context.ServiceLoggerSession;

/**
 * 业务日志拦截器
 * 
 * @author rain
 * @version [版本号, 2016年8月9日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
public abstract class ServiceLoggerHandlerInterceptor extends HandlerInterceptorAdapter {
    
    @Override
    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        ServiceLoggerSession.remove();
    }
    
    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        ServiceLoggerSession.init(request, response, initAttributes(request, response));
        return true;
    }
    
    /** 获取需要初始化的业务日志属性 */
    protected abstract Map<String, Object> initAttributes(HttpServletRequest request, HttpServletResponse response);
}